var gulp = require('gulp');
var gls = require('gulp-live-server');
var webpack = require('gulp-webpack');
var webpackConfig = require('./webpack');
var del = require('del');

process.env.NODE_ENV = 'development'

gulp.task('webpack',['clean'], function() {
    return gulp.src('./')
        .pipe(webpack(webpackConfig))
        .pipe(gulp.dest('dist'));
});

gulp.task('clean', function(cb) {
    del([
        'dist/*'
    ]);
    cb();
});

gulp.task('serve', ['webpack'], function() {

    var notifyFile;
    var server = gls.static('./', 80);
    server.start();

    //use gulp.watch to trigger server actions(notify, start or stop)
    gulp.watch(['./*.html', './src/**'], ['webpack', function() {
        server.notify.apply(server, [notifyFile]);
    }]).on('change', function(file) {
        notifyFile = file
    });
});